var Comm = {
	init : function(){
		$("a[name='vote']").click(function(){
			var id = $(this).attr('rel');
			var type = $(this).attr('class');
			$.ajax({
				type:"POST",
				url:"/pj.php",
				data:{type:type,id:id},
				success:function(msg){
					if(msg == "ok"){
						alert("感谢您的评价O(∩_∩)O~");
						var id = (type=="up"?"#Percent1":"#Percent2");
						var val = parseInt($(id).html())+1;
						$(id).html(val);
					}else if(msg == "false"){
						alert("对不起 您已经顶踩过了");
					}
				}            
			});
		}),
		
		$("#pretech").click(function(){
			if($("a[rel='pretech']").length > 0){
				location.href =  $("a[rel='pretech']").attr("href")
			}else{
				alert("已经没有上一篇了");
			}
		}),

		$("#nexttech").click(function(){
			if($("a[rel='nexttech']").length > 0){
				location.href = $("a[rel='nexttech']").attr("href")
			}else{
				alert("已经没有下一篇了");
			}
		}),

		$(".copybtn").each(function(){
			var num = $(this).attr("rel");
			var codeid = "copycode_"+num;
			var content = decodeURIComponent($("#"+codeid).html());
			copyToClipboard($(this).attr("id"),content);
		})
	}
}

var Comment = {
	origtext : '谈谈您对这篇文章的看法吧···',
	init : function(){
		$("textarea[name='comment']").focus(function(){
			if($(this).val() == Comment.origtext){
				$(this).val('').css("color","#000000");
			}
		}).blur(function(){
			if($(this).val() == ""){
				$(this).css("color","#CCC").val(Comment.origtext);
			}
		})
	},
	check : function(){
		if($("textarea[name='comment']").val().length < 5 || $("textarea[name='comment']").val().length > 200){
			alert("对不起，评论的字数在5-200之间");
			return false;
		}else if($("textarea[name='comment']").val() == Comment.origtext){
			alert("对不起，说点啥再提交吧");
			return false;
		}
		return true;
	}
}

function copyToClipboard(id,content){
	ZeroClipboard.setMoviePath("/script/ZeroClipboard.swf");   
	var clip = new ZeroClipboard.Client(); // 新建一个对象   
	clip.setHandCursor(true); // 设置鼠标为手型 
	clip.setText(content);  
	clip.glue(id);
	clip.addEventListener( "complete", function(){   
		alert("复制成功！");    
	});
}